const glob = require('glob')
const crypto = require('crypto')
const jwt = require('jsonwebtoken')
const resolve = require('path').resolve
const env = require('./env')

exports.globPath = (path, cb) => {
  let result = glob.sync(resolve(path))
  cb(result)
}

exports.Resp = (code, msg, data) => {
  return {code,msg,data}
}

exports.md5Handle = (str, salt) => {
  let md5 = crypto.createHash('md5')
  md5.update(str + salt);
  return md5.digest('hex')
}

exports.jwtSign = (data) => {
  return jwt.sign({
    // 过期时间 1小时   单位/秒
    exp: Math.floor(Date.now() / 1000) + 60*60,
    data: data
  }, env.jwt.secret);
}

exports.jwtVerify = (token) => {
  return jwt.verify(token, env.jwt.secret);
}
